part of _;

extension on ShowPicturePage {
  Widget view_gallery() {
    return MouseMenu(
      items: [
        PopupMenuItem(
          child: Row(
            children: [
              const Icon(Icons.save_alt_rounded, color: Colors.black, size: 20),
              YSpacer(width: 10),
              const Text("保存图片", style: TextStyle(color: Colors.black, fontSize: 14)),
            ],
          ),
          onTap: () => controller_save(),
        ),
      ],
      child: Container(
        color: Colors.black,
        child: PhotoViewGallery.builder(
          pageController: pageController,
          backgroundDecoration: const BoxDecoration(color: Colors.black),
          onPageChanged: (page) => setState(() => index = page),
          enableRotation: false,
          itemCount: pictures.length,
          loadingBuilder: (context, event) => Center(
            child: Container(
              width: 20.0,
              height: 20.0,
              child: CircularProgressIndicator(value: event == null ? 0 : event.cumulativeBytesLoaded / event.expectedTotalBytes!),
            ),
          ),
          builder: (context, index) {
            return PhotoViewGalleryPageOptions(
              imageProvider: ExtendedNetworkImageProvider(pictures[index]),
              initialScale: PhotoViewComputedScale.contained,
              minScale: PhotoViewComputedScale.contained,
              maxScale: PhotoViewComputedScale.covered * 2,
            );
          },
        ),
      ),
    );
  }

  Widget view_num() {
    if (pictures.length <= 1) return YEmpty();
    return Positioned(
      right: 10,
      bottom: MediaQuery.of(context).padding.bottom + 10,
      child: Container(
        padding: const EdgeInsets.fromLTRB(10, 5, 10, 5),
        decoration: BoxDecoration(color: Colors.black.withAlpha(100), borderRadius: BorderRadius.circular(99)),
        child: Text("${index + 1}/${pictures.length}", style: const TextStyle(color: Colors.white, fontSize: 12)),
      ),
    );
  }

  Widget view_page_left() {
    if (index <= 0) return YEmpty();
    return Positioned(
      left: 20,
      child: Container(
        width: 50,
        height: 50,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(99), border: Border.all(color: Colors.white, width: 0.2)),
        child: YInkRoundButton(
          const Icon(Icons.chevron_left_rounded, color: Colors.white),
          onTap: () => pageController!.previousPage(duration: Duration(milliseconds: 300), curve: Curves.linearToEaseOut),
        ),
      ),
    );
  }

  Widget view_page_right() {
    if (pictures.length <= 1 || index >= pictures.length - 1) return YEmpty();
    return Positioned(
      right: 20,
      child: Container(
        width: 50,
        height: 50,
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(99), border: Border.all(color: Colors.white, width: 0.2)),
        child: YInkRoundButton(
          const Icon(Icons.chevron_right_rounded, color: Colors.white),
          onTap: () => pageController!.nextPage(duration: Duration(milliseconds: 300), curve: Curves.linearToEaseOut),
        ),
      ),
    );
  }
}
